package com.kingyun.gpsinspection.purificationservice.services.tdm.innerservice.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.tdm.WorkLinkMapper;
import com.kingyun.gpsinspection.purificationservice.facade.model.tdm.WorkLink;
import com.kingyun.gpsinspection.purificationservice.facade.model.tdm.WorkLinkVo;
import com.kingyun.gpsinspection.purificationservice.facade.service.tdm.WorkLinkService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by jiangjx on 2017/1/16.
 * 作业环节受控管理service实现
 */
public class WorkLinkServiceImpl implements WorkLinkService {

    @Autowired
    private WorkLinkMapper workLinkMapper;

    /**
     * 根据条件查询列表
     *
     * @param workLinkVo 查询条件封装类
     * @return
     */
    @Override
    public JSONObject queryWorkLinkList(WorkLinkVo workLinkVo) {
        /*装载查询条件*/
        workLinkVo.setLimit(null == workLinkVo.getLimit() ? 10 : workLinkVo.getLimit());
        workLinkVo.setOffset(null == workLinkVo.getOffset() ? 0 : workLinkVo.getOffset());
        JSONObject jsonObject = new JSONObject();
        /* 进行分页查询分离 */
        jsonObject.put("total", workLinkMapper.queryCount(workLinkVo));//查询总条数
        List<WorkLink> baseRows = workLinkMapper.queryTableList(workLinkVo);//查询分页内容
        /*返回结果*/
        jsonObject.put("rows", JSON.toJSON(baseRows));
        return jsonObject;
    }

}
